/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2023-01-14
 * Time:15:58
 */
import java.util.Scanner;
class Tree {
    public char val;
    public Tree left;
    public Tree right;
    public Tree(char val) {
        this.val = val;
    }

}
class TreeNode{
    int val;
    TreeNode left;
    TreeNode right;
    public TreeNode(int val){
        this.val=val;
    }
}
// 注意类名必须为 Main, 不要有任何 package xxx 信息
class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String a = in.nextLine();
            Tree root = createTree(a);
            inOrder(root);
        }

    }
    public static void inOrder(Tree root) {
        if (root == null) {
            return;
        }
        inOrder(root.left);
        System.out.print(root.val + " ");
        inOrder(root.right);
    }
    public static int i = 0;
    public static Tree createTree(String str) {
        Tree root = null;
        if (str.charAt(i) != '#') {
            root = new Tree(str.charAt(i));
            i++;
            root.left = createTree(str);
            root.right = createTree(str);
        } else {
            i++;
        }
        return root;
    }
    public boolean isBalanced(TreeNode root) {
        if(root==null){
            return true;
        }
        int right=height(root.right);
        int left=height(root.left);
        int max=right>left?right:left;
        int min=right>left?left:right;
        if(max-min<2){
            return isBalanced(root.left)&&isBalanced(root.right);
        }else{
            return false;
        }
    }
    public int height(TreeNode root){
        if(root==null){
            return 0;
        }
        int right=height(root.right);
        int left=height(root.left);
        return right>left?right+1:left+1;
    }
}

public class Test {

}
